#!/bin/bash -
#===============================================================================
#
#          File: mct.sh
#
#         Usage: ./mct.sh 
#
#   Description: 
#
#       Options: ---
#  Requirements: ---
#          Bugs: ---
#         Notes: ---
#        Author: ShadowStar, <orphen.leiliu@gmail.com>
#  Organization: Gmail
#       Created: 03/28/16 11:40:08
#   Last Change:  08/06/2018 00:44:06
#      Revision:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error
set -f

Usage () {
	echo "Usage: $0 [directory] [file-expr...]"
	exit 0
}

DIR=$(realpath ${PWD})
EXPR_LIST=

if [[ $# -ge 1 && -d "$(realpath $1 2>/dev/null)" ]]; then
	DIR=$(realpath $1)
	shift
fi

if [[ $# -ge 1 ]]; then
	EXPR="$@"
else
	EXPR="*.h *.c *.cpp *.hpp"
fi

for e in ${EXPR}; do
	EXPR_LIST="${EXPR_LIST} -o -iname ${e}"
done

EXPR_LIST=${EXPR_LIST/-o/}

find ${DIR} \( ${EXPR_LIST} \) -print >${PWD}/cscope.files
exuberant-ctags --c-kinds=+px --c++-kinds=+px --fields=+iaS --extra=+q -L cscope.files
cscope -bkq -i cscope.files
